import 'package:flutter/material.dart';
import 'package:flutter_hplus/theme/theme.dart';
import 'package:flutter_hplus/router/router.dart';
import 'package:get/get.dart';
import 'layouts/main_layout.dart';

void main() {
  // 确保Flutter引擎初始化完成
  WidgetsFlutterBinding.ensureInitialized();
  
  // 打印调试信息
  print('应用启动');
  
  // 初始化路由系统
  AppRouter();
  
  // 启动应用
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    print('构建MyApp'); // 添加调试信息
    
    // 使用Miaoyi UI框架的主题系统
    return HThemeProvider(
      theme: HTheme.light(),
      child: MaterialApp(
        title: 'Flutter Miaoyi',
        theme: ThemeData(
          primaryColor: HColors.light().primary,
          scaffoldBackgroundColor: HColors.light().background,
          visualDensity: VisualDensity.adaptivePlatformDensity,
          fontFamily: 'PingFang SC',
          cardTheme: CardTheme(
            color: HTheme.light().colors.cardBackground,
            elevation: 1.0,
          ),
        ),
        // 使用自定义路由生成器
        onGenerateRoute: AppRouter.generateRoute,
        // 启用URL策略（用于Web平台）
        useInheritedMediaQuery: true,
        // 不要使用初始路由，让MainLayout处理初始路由
        initialRoute: null,
        // 使用MainLayout作为应用的根组件
        home: const MainLayout(
          title: 'Flutter Miaoyi UI框架',
          child: SizedBox(), // 子组件会由MainLayout根据当前路由动态加载
        ),
        // 设置主题
        darkTheme: ThemeData.dark().copyWith(
          primaryColor: HTheme.light().colors.primary,
        ),
        debugShowCheckedModeBanner: false,
      ),
    );
  }
}

